<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/homeIndex' }">
        <i class="el-icon-s-custom"></i> 人事管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>员工信息</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>

    <el-row>
      <el-col :span="24">
        <!-- 放搜索条件 
        :inline="ture"让表单元素占一行,一行不够会换行-->
        <el-form :inline="true">
          <el-form-item label="员工姓名">
            <el-input v-model="orderParam.name" placeholder="员工姓名"></el-input>
          </el-form-item>
          <el-form-item label="员工工号">
            <el-input v-model="orderParam.workNum" placeholder="员工工号"></el-input>
          </el-form-item>
          <el-form-item label="电话号码">
            <el-input v-model="orderParam.tel" placeholder="电话号码"></el-input>
          </el-form-item>
          <el-form-item label="职位">
            <el-select placeholder="职位" v-model="orderParam.postid">
              <el-option
                v-for="postid in posts"
                :key="postid.id"
                :label="postid.name"
                :value="postid.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="部门">
            <el-select placeholder="部门" v-model="orderParam.deparid">
              <el-option
                v-for="deparid in departs"
                :key="deparid.id"
                :label="deparid.name"
                :value="deparid.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="登记时间">
            <el-date-picker v-model="orderParam.createTime" placeholder="登记时间"></el-date-picker>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" icon="el-icon-search" @click="queryEmployee">查询</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="clear">重置</el-button>
          </el-form-item>
        </el-form>
      </el-col>

      <el-col :span="24">
        <!-- 放表格数据 -->
        <el-button type="danger" icon="el-icon-plus" @click="addEmployee">新建登记</el-button>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="workNum" label="员工工号" width="180"></el-table-column>
          <el-table-column prop="name" label="员工姓名"></el-table-column>
          <el-table-column prop="gender" label="性别">
            <template slot-scope="scope">{{scope.row.gender == 0?"女":"男"}}</template>
          </el-table-column>
          <el-table-column prop="postName" label="职位"></el-table-column>
          <el-table-column prop="departName" label="部门"></el-table-column>
          <el-table-column prop="tel" label="电话"></el-table-column>
          <el-table-column prop="status" label="状态">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.status === 0 ? 'success' : scope.row.status === 1 ? 'danger' : 'info'"
              >{{ scope.row.status === 0 ? '在职' : scope.row.status === 1 ? '离职' : '其他' }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="230px">
            <template slot-scope="scope">
              <el-button icon="el-icon-edit" type="primary" @click="updateEmp(scope.row.id)">编辑</el-button>
              <el-button icon="el-icon-delete" type="danger" @click="delEmp(scope.row.workNum)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 放分页部分 -->
        <el-pagination
          background
          :page-sizes="[3, 5, 10, 20]"
          :page-size="pageSize"
          :current-page="pageNum"
          layout="total, sizes, prev, pager, next"
          @next-click="nextPage"
          @prev-click="prevPage"
          @size-change="sizeChange"
          @current-change="currentPage"
          :total="total"
        ></el-pagination>
      </el-col>
    </el-row>
  </div>
</template>
    
  <script>
export default {
  data() {
    return {
      pageNum: 1,
      pageSize: 5,
      total: 0,
      posts: [],
      departs: [],
      orderParam: {
        name: "",
        workNum: "",
        tel: "",
        postid: "",
        deparid: "",
        createTime: ""
      },
      tableData: []
    };
  },
  methods: {
    clear() {
      this.orderParam.createTime = "";
      this.orderParam.name = "";
      this.orderParam.workNum = "";
      this.orderParam.tel = "";
      this.orderParam.postid = "";
      this.orderParam.deparid = "";
    },
    prevPage(val) {
      //点击上一页触发
      this.pageNum = val;
      this.queryEmployee();
    },
    nextPage(val) {
      //点击下一页触发
      this.pageNum = val;
      this.queryEmployee();
    },
    sizeChange(val) {
      //val每一页条数
      this.pageNum = 1;
      this.pageSize = val;
      this.queryEmployee();
    },
    currentPage(val) {
      this.pageNum = val;
      this.queryEmployee();
    },
    queryCondition() {
      thispageNum = 1;
      this.queryEmployee();
    },
    queryEmployee() {
      //带分页参数pageNum,pageSize
      let pageParam = {};
      pageParam.pageNum = this.pageNum;
      pageParam.pageSize = this.pageSize;
      pageParam.param = this.orderParam;
      if (this.orderParam.createTime != "") {
        this.orderParam.createTime = this.$moment(
          this.orderParam.createTime
        ).format("YYYY-MM-DD");
      }
      this.$axios.post("api/employee/queryEmployee", pageParam).then(res => {
        if (res.data.code == 200) {
          let pageData = res.data.data;
          this.tableData = pageData.list;
          //给分页参数赋值
          this.total = pageData.total;
          this.pageNum = pageData.pageNum;
          this.pageSize = pageData.pageSize;
        }
      });
    },
    delEmp(val) {
      this.$confirm("确认删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$axios.get("api/employee/deleteEmployee/" + val).then(res => {
            if (res.data.code == 200) {
              //发删除请求
              this.$message.success("删除成功!");
              this.queryEmployee();
            }
          });
        })
        .catch(() => {});
    },
    updateEmp(val) {
      this.$router.push({ path: "/updateEmployee", query: { id: val } });
    },
    addEmployee() {
      this.$router.push({ path: "/addEmployee" });
    },
    queryPost() {
      this.$axios.get("api/post/queryPost").then(res => {
        if (res.data.code == 200) {
          this.posts = res.data.data;
        }
      });
    },
    queryDepart() {
      this.$axios.get("api/depart/queryDepart").then(res => {
        if (res.data.code == 200) {
          this.departs = res.data.data;
        }
      });
    }
  },
  created() {
    this.queryDepart();
    this.queryPost();
    this.queryEmployee();
  }
};
</script>
    
<style scoped>
.el-table {
  margin-top: 20px;
  border-radius: 5px;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}
.el-form-item {
  margin: 10px 50px;
}
.el-button {
  border-radius: 20px;
  text-align: center; /* 文字居中  */
  border: none;
  color: white; /* 文字颜色白色  */
  cursor: pointer;
  display: inline-block;
  background: linear-gradient(
    to right,
    rgb(176, 119, 218),
    rgb(129, 214, 238)
  ); /* 渐变效果更换为浅紫色到浅蓝色 */
  transition-property: background-color, transform; /* 添加过渡属性 */
  transition-duration: 0.3s; /* 过渡持续时间 */
}

.el-button:hover {
  transform: scale(1.1); /* 按钮放大效果  */
  transition: transform 0.3s ease-in-out;
}
.el-col {
  position: relative;
  margin: 1rem;
  padding: 2.5rem;
  background: white;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
  overflow: hidden;
  background: linear-gradient(60deg, #c4dcda 0%, #96e4e1 100%);
}
.el-pagination {
  margin-top: 20px; /* 或者你觉得合适的值 */
}
</style>